var options = {};
var iFrameResizer = {
  messageCallback: function (data) {
    var type = data.type;
    switch (type) {
      case "initialize":
        options = data.data;
        break;
      case "replace":
        document.body.innerHTML = data.content;
        var aList = document.getElementsByTagName("a");
        for (let i = 0; i < aList.length; i++) {
          var aItem = aList[i];
          aItem.onclick = function (e) {
            e.preventDefault();
            let target = e.currentTarget;
            target = target.href ? target : e.target;
            if (target.src === "_blank") {
              window.parentIFrame.sendMessage({
                "type": "jump",
                "uri": target.href
              })
            } else {
              window.parentIFrame.sendMessage({
                "type": "jump",
                "url": target.href
              })
            }
          }
        }
        if (options.photoSwiperUseable) {
          var slides = [];
          var imgList = document.getElementsByTagName("img");
          for (let j = 0; j < imgList.length; j++) {
            var imgItem = imgList[j];
            slides.push({
              src: imgItem.getAttribute("src"),
              thumbnail: imgItem.getAttribute("src")
            });
            imgItem.onclick = function (e) {
              window.parentIFrame.sendMessage({
                "type": "photoView",
                data: [slides, j]
              })
            }
          }
        }
        break;
      default:
        break
    }
  }
};